<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var nums1 = [4,1,2];
        var nums2 = [1,3,4,2];
        var nextGreaterElement = function (nums1, nums2) {
            var arr = nums1.map(item=>{
                var t = nums2.indexOf(item);
                for(t;t<nums2.length;t++){
                    if(nums2[t]>item){
                        return nums2[t]
                    }
                }
                return -1
            })
            return arr;
        }
        console.log(nextGreaterElement(nums1,nums2));
    </script>
</body>
</html>